#!/bin/env bash
source ../config
if $(yarn -v > /dev/null 2>&1)
then
  exit 0
fi
if CheckNetwork
then
  NPMMirror="https://registry.npmmirror.com"
else
  NPMMirror="https://registry.npmjs.org"
fi
echo -e ${yellow}正在设置NPM ${cyan}默认仓库${background}
npm config set registry ${NPMMirror}
npm config set registry ${NPMMirror}
npm install -g npm@latest
echo -e ${yellow}已设置为 ${cyan}${NPMMirror}${background}
echo -e ${yellow}正在安装 ${cyan}YARN${background}
npm install -g yarn
echo -e ${yellow}正在设置YARN ${cyan}默认仓库${background}
yarn config set registry ${NPMMirror}
yarn config set registry ${NPMMirror}
echo -e ${green}已设置为 ${yellow}${NPMMirror}${background}
echo -e ${green}正在安装 ${yellow}PM2${background}
until npm install -g pm2
do
  echo -e ${cyan}安装失败 ${yellow}三秒后重试${background}
  sleep 3s
done
echo -e ${green}安装完成${background}